﻿import { NgModule } from '@angular/core';
import { NavigationEnd, Router, RouterModule } from '@angular/router';
import { AuditLogsComponent } from './audit-logs/audit-logs.component';
import { InstallComponent } from './install/install.component';
import { LanguageTextsComponent } from './languages/language-texts.component';
import { LanguagesComponent } from './languages/languages.component';
import { MaintenanceComponent } from './maintenance/maintenance.component';
import { OrganizationUnitsComponent } from './organization-units/organization-units.component';
import { RolesComponent } from './roles/roles.component';
import { TenantSettingsComponent } from './settings/tenant-settings.component';
import { UiCustomizationComponent } from './ui-customization/ui-customization.component';
import { UsersComponent } from './users/users.component';

@NgModule({
    imports: [
        RouterModule.forChild([
            {
                path: '',
                children: [
                    { path: 'users', component: UsersComponent, data: { permission: 'Pages.Administration.Users' } },
                    { path: 'roles', component: RolesComponent, data: { permission: 'Pages.Administration.Roles' } },
                    {
                        path: 'auditLogs',
                        component: AuditLogsComponent,
                        data: { permission: 'Pages.Administration.AuditLogs' }
                    },
                    {
                        path: 'maintenance',
                        component: MaintenanceComponent,
                        data: { permission: 'Pages.Administration.Host.Maintenance' }
                    },
                    {
                        path: 'languages',
                        component: LanguagesComponent,
                        data: { permission: 'Pages.Administration.Languages' }
                    },
                    {
                        path: 'languages/:name/texts',
                        component: LanguageTextsComponent,
                        data: { permission: 'Pages.Administration.Languages.ChangeTexts' }
                    },
                    {
                        path: 'organization-units',
                        component: OrganizationUnitsComponent,
                        data: { permission: 'Pages.Administration.OrganizationUnits' }
                    },
                    {
                        path: 'tenantSettings',
                        component: TenantSettingsComponent,
                        data: { permission: 'Pages.Administration.Tenant.Settings' }
                    },
                    { path: 'install', component: InstallComponent },
                    { path: 'ui-customization', component: UiCustomizationComponent }
                ]
            }
        ])
    ],
    exports: [RouterModule]
})
export class AdminRoutingModule {
    constructor(private router: Router) {
        router.events.subscribe(event => {
            if (event instanceof NavigationEnd) {
                window.scroll(0, 0);
            }
        });
    }
}
